<?php
/* Setup Timezone */
date_default_timezone_set('US/Pacific');

require $userconfig->mainconfig['v4rootdir'].'lib/master.lib.php';

/* Create $masterclass Object */
$masterclass=new master();
/* GLOBALS $masterclass */
$GLOBALS['masterclass']=$masterclass;

/* Setup Static $masterclass Arrays */
$masterclass->allclasses=array();
$masterclass->site=array();
$masterclass->sitevars=array();
$masterclass->mainconfig=array();
$masterclass->websiteconfig=array();
if (!empty($userconfig->site)) { foreach ($userconfig->site as $mckey=>$mcval) { $masterclass->site[$mckey]=$mcval; } }
if (!empty($userconfig->mainconfig)) { foreach ($userconfig->mainconfig as $mckey=>$mcval) { $masterclass->mainconfig[$mckey]=$mcval; } }
if (!empty($userconfig->websiteconfig)) { foreach ($userconfig->websiteconfig as $mckey=>$mcval) { $masterclass->websiteconfig[$mckey]=$mcval; } }


/* Setup Configuration Options */
if (is_file($masterclass->mainconfig['v4rootdir'].'include/defaultconfig.inc.php')) { $defaultfile=$masterclass->mainconfig['v4rootdir'].'include/defaultconfig.inc.php'; }
else if (is_file('defaultconfig.inc.php.php')) { $defaultfile='defaultconfig.inc.php'; }
else if (is_file('../defaultconfig.inc.php')) { $defaultfile='../defaultconfig.inc.php'; }
else if (is_file('../include/defaultconfig.inc.php')) { $defaultfile='../include/defaultconfig.inc.php'; }

if (is_file('userconfig.php')) { $userfile='userconfig.php'; }
else if (is_file('../userconfig.php')) { $userfile='../userconfig.php'; }
else if (is_file('../include/userconfig.php')) { $userfile='../include/userconfig.php'; }

if ($defaultfile!='' && is_file($defaultfile)) {
  $tmparr=$masterclass->load_config($defaultfile);
  if (!empty($tmparr)) {
    foreach ($tmparr as $obj=>$val) { $masterclass->$obj=array_merge($masterclass->$obj,$tmparr->$obj); }
  }
} else { echo "FATAL ERROR!!: Cannot Find Default Config File, Call Admin!";exit(); }
if ($userfile!='' && is_file($userfile)) {
  $tmparr=$masterclass->load_config($userfile);
  if (!empty($tmparr)) {
    foreach ($tmparr as $obj=>$val) { $masterclass->$obj=array_merge($masterclass->$obj,$tmparr->$obj); }
  }
}  else { echo "ERROR: Cannot Find Users Config File"; }


/* Setup Mobile Support */
require $userconfig->mainconfig['v4rootdir'].'lib/php-to-detect-mobile-phones.php';
if (detect_mobile_device()) {
  $masterclass->mainconfig['iswapdevice']='1';
  $masterclass->mainconfig['sourcedirectory']=$userconfig->mainconfig['sourcewapdirectory'];
  $masterclass->websiteconfig['page_procesing']='';
}

/* Include MYSQL Support */
if ($masterclass->mainconfig['include_mysql']=='1') {
  require $masterclass->mainconfig['v4rootdir'].'lib/mysql_functions.lib.php';
  $masterclass->allclasses['mysql_functions']=new mysql_functions();
  $masterclass->allclasses['mysql_functions']->create_dbconnect($masterclass->mainconfig['database_host'],$masterclass->mainconfig['default_database'],$masterclass->mainconfig['database_login'],$masterclass->mainconfig['database_pass']);
}
/* Include ADODB MYSQL Support */
if ($masterclass->mainconfig['include_adodb']=='1') {
  require $masterclass->mainconfig['v4rootdir'].'lib/adodb/adodb.inc.php';
  $masterclass->allclasses['adodb'] = NewADOConnection($masterclass->mainconfig['datastorage']);
  $masterclass->allclasses['adodb']->Connect($masterclass->mainconfig['database_host'],$masterclass->mainconfig['database_login'],$masterclass->mainconfig['database_pass'],$masterclass->mainconfig['default_database']);
}

/* Grab site Object variables */
if (isset($_REQUEST) && !empty($_REQUEST)) {
  $masterclass->site['displaypage']=$_REQUEST['pg']; if ($masterclass->site['displaypage']=='' || $masterclass->site['displaypage']<=0) { $masterclass->site['displaypage']=1; }
  $masterclass->site['dirpath']=$_REQUEST['dirpath'];
  $masterclass->site['page']=$_REQUEST['page'];
} else
if (isset($argv) && $argc>0) {
  $masterclass->site['page']=$argv[1];
  if (isset($argc[2])) { $masterclass->site['dirpath']=$argv[2]; }
  if (isset($argv[3])) {
    $masterclass->site['displaypage']=$argv[3];
    if ($masterclass->site['displaypage']=='' || $masterclass->site['displaypage']<=0) { $masterclass->site['displaypage']=1; }
  }
}

if ($masterclass->site['page']=='') { $masterclass->site['page']=$masterclass->mainconfig['defaultpage']; }

function datecomp($a, $b)
{
  return ($a[1] < $b[1]) ? -1 : 0;
}
?>